using System;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using Evaluant.Uss.ObjectContext;
using Evaluant.Uss;


namespace NUnit.Mapping.Culture
{
	
    [TestClass]
	public class Fixture
	{
        protected ObjectContext oc;
        protected Evaluant.Uss.SqlMapper.SqlMapperProvider provider;

        public Fixture()
        {
            provider = new Evaluant.Uss.SqlMapper.SqlMapperProvider();
            
            provider.ConnectionString = @"Data Source=.;Initial Catalog=uss;Integrated Security=True";
            provider.Dialect = "Evaluant.Uss.SqlMapper.MsSqlDialect";
            provider.Driver = "Evaluant.Uss.SqlMapper.MsSqlDriver";
            provider.MappingFileName = @"..\..\..\NUnit\Mapping\Culture\mapping_1.xml";
            provider.TablePrefix = "CULT_";
            provider.RegisterMetaData(MetaDataFactory.FromAssembly(typeof(Person).Assembly));

        }

        [TestMethod]
        public void SerializeDecimalUsingCulture()
        {
            provider.Culture = new System.Globalization.CultureInfo("en-US");
            provider.InitializeConfiguration();
            oc = new ObjectService(provider).CreateObjectContext();

            oc.InitializeRepository();

            // Create
            Person p = new Person();
            p.Name = "Bob";
            p.Age = 23;
            p.Weight = 102.34m;

            oc.BeginTransaction();
            oc.Serialize(p);
            oc.CommitTransaction();

            oc.Clear();

            p = oc.LoadSingle<Person>();

            Assert.AreEqual(102.34m, p.Weight);
        }
    }
}
